﻿@model IkoulaACDF.Models.EditUserViewModel

@section Scripts {
    @*@Scripts.Render("~/bundles/datetimepicker")*@
    @Scripts.Render("~/bundles/inputmask")
    @Scripts.Render("~/bundles/jqueryval")


    @*<script>
           $(document).ready(function () {
               $(".date-picker").datepicker({
                   language: "@System.Globalization.CultureInfo.CurrentUICulture.Name",
               });
           });
    </script>}*@

    <script>
        $(document).ready(function () {
            $("#BirthDate").inputmask("d/m/y", { "placeholder": "dd/mm/yyyy" });
        });
    </script>

}

@{
    ViewBag.Title = "Edit";
}

<p class="text-success">@ViewBag.StatusMessage</p>

<h2>Edition du profil de @Html.DisplayFor(model => model.UserName)</h2>

@using (Html.BeginForm("Edit", "Account", FormMethod.Post, new { @class = "form-horizontal", role = "form", enctype = "multipart/form-data" }))
{
    <div class="form-horizontal">
            @Html.AntiForgeryToken()
        <div class="container">
            @Html.ValidationSummary(true)

            <div class="form-group">
                @Html.LabelFor(model => model.UserName, new { @class = "control-label col-md-2" })
                <div class="col-md-10">
                    @*BUG: User Name in Edit view must be read only ==> Corrected in Edit view change from EditFor to TextBoxFor*@
                    @Html.TextBoxFor(model => model.UserName, new { @class = "form-control", placeholder = "User name", @readonly = "readonly" })
                    @Html.ValidationMessageFor(model => model.UserName)
                </div>
            </div>

            <div class="form-group">
                @Html.LabelFor(model => model.FirstName, new { @class = "control-label col-md-2" })
                <div class="col-md-10">
                    @Html.TextBoxFor(model => model.FirstName, new { @class = "form-control", placeholder = "First name" })
                    @Html.ValidationMessageFor(model => model.FirstName)
                </div>
            </div>

            <div class="form-group">
                @Html.LabelFor(model => model.LastName, new { @class = "control-label col-md-2" })
                <div class="col-md-10">
                    @Html.TextBoxFor(model => model.LastName, new { @class = "form-control", placeholder = "Last name" })
                    @Html.ValidationMessageFor(model => model.LastName)
                </div>
            </div>

            <div class="form-group">
                @Html.LabelFor(model => model.Email, new { @class = "control-label col-md-2" })
                <div class="col-md-10">
                    @Html.TextBoxFor(model => model.Email, new { @class = "form-control", placeholder = "Email" })
                    @Html.ValidationMessageFor(model => model.Email)
                </div>
            </div>
            <div class="form-group">
                @Html.LabelFor(model => model.BirthDate, new { @class = "col-md-2 control-label" })
                <div class="col-md-10">
                    @*@Html.TextBoxFor(model => model.BirthDate, new { @class = "form-control" })*@
                    @*@Html.TextBoxFor(model => model.BirthDate, new { @class = "form-control date-picker", value = Model.BirthDate.ToString("dd-mm-yyyy") })*@
                    @*@Html.EditorFor(model => model.BirthDate)*@
                    @Html.TextBoxFor(model => model.BirthDate, new { @class = "form-control" })
                    @Html.ValidationMessageFor(model => model.BirthDate)
                </div>
            </div>
            <div class="form-group">
                @Html.LabelFor(model => model.FirstYearSchool, new { @class = "col-md-2 control-label" })
                <div class="col-md-10">
                    @*@Html.TextBoxFor(model => model.FirstYearSchool, new { @class = "form-control" })*@
                    @Html.DropDownListFor(model => model.FirstYearSchool, new SelectList(Model.YearFirst, "Value", "Text"), new { selected = "model => model.FirstYearSchool" })
                </div>
            </div>
            <div class="form-group">
                @Html.LabelFor(model => model.LastYearSchool, new { @class = "col-md-2 control-label" })
                <div class="col-md-10">
                    @*@Html.TextBoxFor(model => model.LastYearSchool, new { @class = "form-control" })*@
                    @Html.DropDownListFor(model => model.LastYearSchool, new SelectList(Model.YearLast, "Value", "Text"), new { selected = "model => model.LastYearSchool" })
                </div>
            </div>
            <div class="form-group">
                @Html.LabelFor(model => model.LastClass, new { @class = "col-md-2 control-label" })
                <div class="col-md-10">
                    @Html.TextBoxFor(model => model.LastClass, new { @class = "form-control" })
                </div>
            </div>
            <div class="form-group">
                @Html.LabelFor(model => model.ActualCity, new { @class = "col-md-2 control-label" })
                <div class="col-md-10">
                    @Html.TextBoxFor(model => model.ActualCity, new { @class = "form-control" })
                </div>
            </div>
            <div class="form-group">
                @Html.LabelFor(model => model.ActualCountry, new { @class = "col-md-2 control-label" })
                <div class="col-md-10">
                    @Html.TextBoxFor(model => model.ActualCountry, new { @class = "form-control" })
                </div>
            </div>


            <div class="form-group">
                @Html.Label("Actual photo", new { @class = "col-md-2 control-label" })
                <div class="col-md-10">
                    <img src="@Html.DisplayFor(model => model.PhotoUrl)" alt="@Html.DisplayFor(model => model.UserName) " width="100" title="@Html.DisplayFor(model => model.FirstName)" />
                </div>
            </div>
            <div class="form-group">
                @Html.LabelFor(model => model.Photo, new { @class = "col-md-2 control-label" })
                <div class="col-md-10">
                    @Html.TextBoxFor(model => model.Photo, null, new { id = "FilePhoto", onchange = "readURL(this)", type = "file", title = "Search for file to add", @class = "btn btn-primary" })
                    @Html.ValidationMessageFor(model => model.Photo)<br />
                    <img id="blah" src="#" alt="" width="100" />
                </div>
            </div>

            @* if user don't have photo don't propose to remove it*@
            @if (!(Model.PhotoUrl.Contains("BlankPhoto.jpg")))
            {
                <div class="form-group">
                    @Html.LabelFor(model => model.IsNoPhotoChecked, new { @class = "col-md-2 control-label" })
                    <div class="col-md-10">
                        @Html.CheckBoxFor(model => model.IsNoPhotoChecked)
                    </div>
                </div>
            }
            @*TODO: For now admin cannot reset user password, he can only change his password.*@
                @*So we hide this to admin or dev as admin, when editing a user*@
                @if (User.Identity.Name == Model.UserName)
                {
                    <div class="form-group">
                        @Html.Label("Mot de passe", new { @class = "control-label col-md-2" })
                        <div class="col-md-10">
                            @Html.ActionLink("Changer votre mot de passe", "Manage", "Account", routeValues: null, htmlAttributes: new { title = "Administrer mot de passe" })
                        </div>
                    </div>
                }
                <div class="form-group">
                    @Html.LabelFor(model => model.RegistrationDate, new { @class = "col-md-2 control-label" })
                    <div class="col-md-10">
                        @Html.TextBoxFor(model => model.RegistrationDate, new { @class = "form-control", @readonly = "readonly" })
                    </div>
                </div>

                <div class="form-group">
                    <div class="col-md-offset-2 col-md-10">
                        <input type="submit" value="Save" class="btn btn-default" />
                    </div>
                </div>
            </div>
            </div>
}
<div>
    <span class="btn btn-default">@Html.ActionLink("Back to List", "Index")</span>
</div>
